#include "FpsCtrl.h"


FpsCtrl::FpsCtrl (double fr) :
time (0), oldTime (0), dTime (0),
frameRate (fr), frameCount (0),
width (0), height (0)
{
}
bool FpsCtrl::update (const int &w, const int &h)
{
   width = w;
   height = h;
   time = glutGet (GLUT_ELAPSED_TIME);
   dTime = time - oldTime;
   if (dTime >= 1000.0 / frameRate) {//1000.0 = 1.0 second
      frameCount++;
      oldTime = time;
      setWindowTitle ();
      return true;
   }
   frameCount = 0;
   return false;
}
void FpsCtrl::setWindowTitle (void)
{
   if (frameCount != 0) {
      char TempString[512];
      sprintf (TempString, "Simulador de Pneumatica: %d Frames Por Segundo @ %d x %d\0", frameCount*(int)frameRate, width, height);
      glutSetWindowTitle (TempString);
   }

}
void FpsCtrl::setFrameRate (const double &fr)
{
   frameRate = fr;
}
const double &FpsCtrl::getFrameRate (void)
{
   return frameRate;
}
FpsCtrl::~FpsCtrl ()
{
}
